/* eslint-disable */
import { MENU_CODES, METHOD_TYPE, MODULES } from '@/options';
import useBaseRequest from '@/hooks/useBaseRequest';
import { SortOrder } from 'antd/lib/table/interface';
import { request } from '@umijs/max';
import { BaseListUrl, PageType, ResultPage } from '@/types/common/request';

type DataType = MENU_TYPE.Info;
type Params = MENU_TYPE.Params;
const ApiUrl = `/${MODULES.SYSTEM}/${MENU_CODES.MENU}`;

export const { addItem, updateItem, delItem, detailItem } = useBaseRequest<DataType, Params>(
  ApiUrl,
);

export const getTreeList = async (
  params?: Partial<Params> & PageParams,
  sort?: Record<string, SortOrder>,
  filter?: Record<string, (string | number)[] | null>,
  options?: { [key: string]: any },
): Promise<PageType<DataType>> => {
  // console.log(params, sort, filter, options);
  const ret = await request<ResultPage<DataType>>(ApiUrl + BaseListUrl.TREE_LIST, {
    method: METHOD_TYPE.GET,
    params: {
      current: 1,
      pageSize: -1,
      ...params,
    },
    ...(options || {}),
  });
  return {
    success: ret.success,
    message: ret.message,
    code: ret.code,
    ...ret.data,
  };
};
